<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>新增外出记录</title>
    <link rel="stylesheet" href="css/bootstrap.css">
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.js"></script>
    <script src="js/common.js" type="text/javascript"></script>
    <script src="js/jsrender.js"></script>
    <script type="text/javascript">
        $(function () {
            if(localStorage.getItem("token")==null){
                window.location.href="login.html"
            }
            var cid
            if(localStorage.getItem("customerid")!=null){
        		cid = localStorage.getItem("customerid")
        		
        	}
        	else{
        		cid = null
        	}
            $("#customerid").val(cid)
            
            
            var today = new Date();
            var nowDate= today.getFullYear() +
                "-" + (today.getMonth()+1<10?"0"+(today.getMonth()+1):(today.getMonth()+1)) +
                "-" + (today.getDate()<10?"0"+today.getDate():today.getDate());
            $("#gooutdate").val(nowDate)
            //注册转换器
            $.views.converters("dateformat" , function (val) {
                var mydate = new Date(val)
                var y = mydate.getFullYear()
                var m = mydate.getMonth()+1
                var d = mydate.getDate()
                return y + "-" + (m < 10 ? "0" + m : m) + "-" + (d < 10 ? "0" + d : d)
            })
            $("form").submit(function(){
                $.ajax({
                    url:GC.bctx + "customers/goout",
                    type:"POST",
                    data:$("form").serialize(),
                    headers: {"Authorization": localStorage.getItem("token")},
                    success:function(r){
                        if(r.successed){
                            //新增成功，转向显示外出记录页面
                            alert(r.message)
                            window.location.href="listGoout.html"
                        }else{
                            //新增失败，显示失败信息
                            alert(r.message)
                        }

                    }
                })
                return false
            })
            
        })
    </script>

</head>
<body>

<div class="container-fluid">
    <h1>登记外出</h1>
    <hr/>
    <form>
        <table>
            <tr>
                <td>离院日期：</td>
                <td><input id="gooutdate" name="gooutdate" type="date"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr>
                <td>预期返回日期：</td>
                <td><input id="expectedbackdate" name="expectedbackdate" type="date"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr>
                <td>客户id：</td>
                <td><input id="customerid" name="customerid"  type="text"/></td>
                <td><span class="c-r">*</span></td>
            </tr>
            <tr>
                <td>离院原因：</td>
                <td><input id="gooutreason" name="gooutreason" type="text" /></td>
                <td><span class="c-r">*</span></td>
            </tr>
			<tr>
                <td colspan="3" class="text-center">
                    <input type="submit" value="保存"/>
                    <input type="reset" value="重置"/>
                </td>
            </tr>


        </table>
    </form>
</div>
</body>
</html>